<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Hash function</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Hash_function"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.math.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Hash_function rootpage-Hash_function skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Hash function</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">"hashlink" redirects here. For the Haxe virtual machine, see <a href="HashLink" class="mw-redirect" title="HashLink">HashLink</a>.</div>
<div role="note" class="hatnote navigation-not-searchable">"Hash code" redirects here. For the programming competition, see <a href="Hash_Code_(programming_competition)" title="Hash Code (programming competition)">Hash Code (programming competition)</a>.</div>
<div role="note" class="hatnote navigation-not-searchable">This article is about a computer programming construct. For other meanings of "hash" and "hashing", see <a href="Hash_(disambiguation)" class="mw-redirect mw-disambig" title="Hash (disambiguation)">Hash (disambiguation)</a>.</div>
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */
.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style>
<p>A <b>hash function</b> is any <a href="Function_(mathematics)" title="Function (mathematics)">function</a> that can be used to map <a href="Data_(computing)" class="mw-redirect" title="Data (computing)">data</a> of arbitrary size to fixed-size values, though there are some hash functions that support variable-length output.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> The values returned by a hash function are called <i>hash values</i>, <i>hash codes</i>, (<i>hash/message</i>) <i>digests</i>,<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> or simply <i>hashes</i>. The values are usually used to index a fixed-size table called a <i><a href="Hash_table" title="Hash table">hash table</a></i>. Use of a hash function to index a hash table is called <i>hashing</i> or <i>scatter-storage addressing</i>.
</p><p>Hash functions and their associated hash tables are used in data storage and retrieval applications to access data in a small and nearly constant time per retrieval. They require an amount of storage space only fractionally greater than the total space required for the data or records themselves. Hashing is a computationally- and storage-space-efficient form of data access that avoids the non-constant access time of ordered and unordered lists and structured trees, and the often-exponential storage requirements of direct access of state spaces of large or variable-length keys.
</p><p>Use of hash functions relies on statistical properties of key and function interaction: worst-case behavior is intolerably bad but rare, and average-case behavior can be nearly optimal (minimal <a href="Hash_collision" title="Hash collision">collision</a>).<sup id="cite_ref-knuth-1973_3-0" class="reference"><a href="#cite_note-knuth-1973-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup><sup class="reference nowrap"><span title="Page: 527">: 527 </span></sup>
</p><p>Hash functions are related to (and often confused with) <a href="Checksums" class="mw-redirect" title="Checksums">checksums</a>, <a href="Check_digit" title="Check digit">check digits</a>, <a href="Fingerprint_(computing)" title="Fingerprint (computing)">fingerprints</a>, <a href="Lossy_compression" title="Lossy compression">lossy compression</a>, <a href="Randomization_function" class="mw-redirect" title="Randomization function">randomization functions</a>, <a href="Error_correction_code" title="Error correction code">error-correcting codes</a>, and <a href="Cipher" title="Cipher">ciphers</a>. Although the concepts overlap to some extent, each one has its own uses and requirements and is designed and optimized differently. The hash function differs from these concepts mainly in terms of <a href="Data_integrity" title="Data integrity">data integrity</a>. Hash tables may use <a href="Non-cryptographic_hash_function" title="Non-cryptographic hash function">non-cryptographic hash functions</a>, while <a href="Cryptographic_hash_function" title="Cryptographic hash function">cryptographic hash functions</a> are used in cybersecurity to secure sensitive data such as passwords.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Overview">Overview</h2></div>
<p>In a hash table, a hash function takes a key as an input, which is associated with a datum or record and used to identify it to the data storage and retrieval application. The keys may be fixed-length, like an integer, or variable-length, like a name. In some cases, the key is the datum itself. The output is a hash code used to index a hash table holding the data or records, or pointers to them.
</p><p>A hash function may be considered to perform three functions:
</p>
<ul><li>Convert variable-length keys into fixed-length (usually <a href="Machine_word" class="mw-redirect" title="Machine word">machine-word</a>-length or less) values, by folding them by words or other units using a <a href="Parity_function" title="Parity function">parity-preserving operator</a> like ADD or XOR,</li>
<li>Scramble the bits of the key so that the resulting values are uniformly distributed over the <a href="Key_space_(cryptography)" class="mw-redirect" title="Key space (cryptography)">keyspace</a>, and</li>
<li>Map the key values into ones less than or equal to the size of the table.</li></ul>
<p>A good hash function satisfies two basic properties: it should be very fast to compute, and it should minimize duplication of output values (<a href="Hash_collision" title="Hash collision">collisions</a>). Hash functions rely on generating favorable <a href="Probability_distribution" title="Probability distribution">probability distributions</a> for their effectiveness, reducing access time to nearly constant. High table loading factors, <a href="Pathological_(mathematics)" title="Pathological (mathematics)">pathological</a> key sets, and poorly designed hash functions can result in access times approaching linear in the number of items in the table. Hash functions can be designed to give the best worst-case performance,<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>Notes 1<span class="cite-bracket">]</span></a></sup> good performance under high table loading factors, and in special cases, perfect (collisionless) mapping of keys into hash codes. Implementation is based on parity-preserving bit operations (XOR and ADD), multiply, or divide. A necessary adjunct to the hash function is a collision-resolution method that employs an auxiliary data structure like <a href="Linked_list" title="Linked list">linked lists</a>, or systematic probing of the table to find an empty slot.
</p>
<div class="mw-heading mw-heading2"><h2 id="Hash_tables">Hash tables</h2></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Hash_table" title="Hash table">Hash table</a></div>
<p>Hash functions are used in conjunction with <a href="Hash_tables" class="mw-redirect" title="Hash tables">hash tables</a> to store and retrieve data items or data records. The hash function translates the key associated with each datum or record into a hash code, which is used to index the hash table. When an item is to be added to the table, the hash code may index an empty slot (also called a bucket), in which case the item is added to the table there. If the hash code indexes a full slot, then some kind of collision resolution is required: the new item may be omitted (not added to the table), or replace the old item, or be added to the table in some other location by a specified procedure. That procedure depends on the structure of the hash table. In <i>chained hashing</i>, each slot is the head of a linked list or chain, and items that collide at the slot are added to the chain. Chains may be kept in random order and searched linearly, or in serial order, or as a self-ordering list by frequency to speed up access. In <i>open address hashing</i>, the table is probed starting from the occupied slot in a specified manner, usually by <a href="Linear_probing" title="Linear probing">linear probing</a>, <a href="Quadratic_probing" title="Quadratic probing">quadratic probing</a>, or <a href="Double_hashing" title="Double hashing">double hashing</a> until an open slot is located or the entire table is probed (overflow). Searching for the item follows the same procedure until the item is located, an open slot is found, or the entire table has been searched (item not in table).
</p>
<div class="mw-heading mw-heading3"><h3 id="Specialized_uses">Specialized uses</h3></div>
<p>Hash functions are also used to build <a href="Cache_(computing)" title="Cache (computing)">caches</a> for large data sets stored in slow media. A cache is generally simpler than a hashed search table, since any collision can be resolved by discarding or writing back the older of the two colliding items.<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>
</p><p>Hash functions are an essential ingredient of the <a href="Bloom_filter" title="Bloom filter">Bloom filter</a>, a space-efficient <a href="Probability" title="Probability">probabilistic</a> <a href="Data_structure" title="Data structure">data structure</a> that is used to test whether an <a href="Element_(mathematics)" title="Element (mathematics)">element</a> is a member of a <a href="Set_(computer_science)" class="mw-redirect" title="Set (computer science)">set</a>.
</p><p>A special case of hashing is known as <a href="Geometric_hashing" title="Geometric hashing">geometric hashing</a> or the <i>grid method</i>. In these applications, the set of all inputs is some sort of <a href="Metric_space" title="Metric space">metric space</a>, and the hashing function can be interpreted as a <a href="Partition_(mathematics)" class="mw-redirect" title="Partition (mathematics)">partition</a> of that space into a grid of <i>cells</i>. The table is often an array with two or more indices (called a <i><a href="Grid_file" title="Grid file">grid file</a></i>, <i>grid index</i>, <i>bucket grid</i>, and similar names), and the hash function returns an index <a href="Tuple" title="Tuple">tuple</a>. This principle is widely used in <a href="Computer_graphics" title="Computer graphics">computer graphics</a>, <a href="Computational_geometry" title="Computational geometry">computational geometry</a>, and many other disciplines, to solve many <a href="Proximity_problem" class="mw-redirect" title="Proximity problem">proximity problems</a> in the <a href="Plane_(geometry)" class="mw-redirect" title="Plane (geometry)">plane</a> or in <a href="Three-dimensional_space" title="Three-dimensional space">three-dimensional space</a>, such as finding <a href="Closest_pair_problem" class="mw-redirect" title="Closest pair problem">closest pairs</a> in a set of points, similar shapes in a list of shapes, similar <a href="Image_processing" class="mw-redirect" title="Image processing">images</a> in an <a href="Image_retrieval" title="Image retrieval">image database</a>, and so on.
</p><p>Hash tables are also used to implement <a href="Associative_array" title="Associative array">associative arrays</a> and <a href="Set_(abstract_data_type)" title="Set (abstract data type)">dynamic sets</a>.<sup id="cite_ref-handbook_of_applied_cryptography_6-0" class="reference"><a href="#cite_note-handbook_of_applied_cryptography-6"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Properties">Properties</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Uniformity">Uniformity</h3></div>
<p>A good hash function should map the expected inputs as evenly as possible over its output range. That is, every hash value in the output range should be generated with roughly the same <a href="Probability" title="Probability">probability</a>. The reason for this last requirement is that the cost of hashing-based methods goes up sharply as the number of <i>collisions</i>—pairs of inputs that are mapped to the same hash value—increases. If some hash values are more likely to occur than others, then a larger fraction of the lookup operations will have to search through a larger set of colliding table entries.
</p><p>This criterion only requires the value to be <i>uniformly distributed</i>, not <i>random</i> in any sense. A good randomizing function is (barring computational efficiency concerns) generally a good choice as a hash function, but the converse need not be true.
</p><p>Hash tables often contain only a small subset of the valid inputs. For instance, a club membership list may contain only a hundred or so member names, out of the very large set of all possible names. In these cases, the uniformity criterion should hold for almost all typical subsets of entries that may be found in the table, not just for the global set of all possible entries.
</p><p>In other words, if a typical set of <span class="texhtml"><i>m</i></span> records is hashed to <span class="texhtml"><i>n</i></span> table slots, then the probability of a bucket receiving many more than <span class="texhtml"><i>m</i>/<i>n</i></span> records should be vanishingly small. In particular, if <span class="texhtml"><i>m</i> < <i>n</i></span>, then very few buckets should have more than one or two records. A small number of collisions is virtually inevitable, even if <span class="texhtml"><i>n</i></span> is much larger than <span class="texhtml"><i>m</i></span>—see the <a href="Birthday_problem" title="Birthday problem">birthday problem</a>.
</p><p>In special cases when the keys are known in advance and the key set is static, a hash function can be found that achieves absolute (or collisionless) uniformity. Such a hash function is said to be <i><a href="Perfect_hash_function" title="Perfect hash function">perfect</a></i>. There is no algorithmic way of constructing such a function—searching for one is a <a href="Factorial" title="Factorial">factorial</a> function of the number of keys to be mapped versus the number of table slots that they are mapped into. Finding a perfect hash function over more than a very small set of keys is usually computationally infeasible; the resulting function is likely to be more computationally complex than a standard hash function and provides only a marginal advantage over a function with good statistical properties that yields a minimum number of collisions. See <a href="Universal_hashing" title="Universal hashing">universal hash function</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Testing_and_measurement">Testing and measurement</h3></div>
<p>When testing a hash function, the uniformity of the distribution of hash values can be evaluated by the <a href="Chi-squared_test" title="Chi-squared test">chi-squared test</a>. This test is a goodness-of-fit measure: it is the actual distribution of items in buckets versus the expected (or uniform) distribution of items. The formula is
</p><p><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {\sum _{j=0}^{m-1}(b_{j})(b_{j}+1)/2}{(n/2m)(n+2m-1)}},}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
<mo>=</mo>
<mn>0</mn>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>m</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</munderover>
<mo stretchy="false">(</mo>
<msub>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">(</mo>
<msub>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
</mrow>
</msub>
<mo>+</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
</mrow>
<mrow>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
<mi>m</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mo>+</mo>
<mn>2</mn>
<mi>m</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</mfrac>
</mrow>
<mo>,</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\frac {\sum _{j=0}^{m-1}(b_{j})(b_{j}+1)/2}{(n/2m)(n+2m-1)}},}</annotation>
</semantics>
</math></span><img src="./20683f81d6348d2f2448b18ea4bf80d06242cff8.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.671ex; width:22.302ex; height:7.343ex;" alt="{\displaystyle {\frac {\sum _{j=0}^{m-1}(b_{j})(b_{j}+1)/2}{(n/2m)(n+2m-1)}},}" loading="lazy"></span>
</p><p>where <span class="texhtml mvar" style="font-style:italic;">n</span> is the number of keys, <span class="texhtml mvar" style="font-style:italic;">m</span> is the number of buckets, and <span class="texhtml"><i>b</i><sub><i>j</i></sub></span> is the number of items in bucket <span class="texhtml mvar" style="font-style:italic;">j</span>.
</p><p>A ratio within one confidence interval (such as 0.95 to 1.05) is indicative that the hash function evaluated has an expected uniform distribution.
</p><p>Hash functions can have some technical properties that make it more likely that they will have a uniform distribution when applied. One is the <a href="Strict_avalanche_criterion" class="mw-redirect" title="Strict avalanche criterion">strict avalanche criterion</a>: whenever a single input bit is complemented, each of the output bits changes with a 50% probability. The reason for this property is that selected subsets of the keyspace may have low variability. For the output to be uniformly distributed, a low amount of variability, even one bit, should translate into a high amount of variability (i.e. distribution over the tablespace) in the output. Each bit should change with a probability of 50% because, if some bits are reluctant to change, then the keys become clustered around those values. If the bits want to change too readily, then the mapping is approaching a fixed XOR function of a single bit. Standard tests for this property have been described in the literature.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup> The relevance of the criterion to a multiplicative hash function is assessed here.<sup id="cite_ref-fibonacci-hashing_8-0" class="reference"><a href="#cite_note-fibonacci-hashing-8"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Efficiency">Efficiency</h3></div>
<p>In data storage and retrieval applications, the use of a hash function is a trade-off between search time and data storage space. If search time were unbounded, then a very compact unordered linear list would be the best medium; if storage space were unbounded, then a randomly accessible structure indexable by the key-value would be very large and very sparse, but very fast. A hash function takes a finite amount of time to map a potentially large keyspace to a feasible amount of storage space searchable in a bounded amount of time regardless of the number of keys. In most applications, the hash function should be computable with minimum latency and secondarily in a minimum number of instructions.
</p><p>Computational complexity varies with the number of instructions required and latency of individual instructions, with the simplest being the bitwise methods (folding), followed by the multiplicative methods, and the most complex (slowest) are the division-based methods.
</p><p>Because collisions should be infrequent, and cause a marginal delay but are otherwise harmless, it is usually preferable to choose a faster hash function over one that needs more computation but saves a few collisions.
</p><p>Division-based implementations can be of particular concern because a division requires multiple cycles on nearly all processor <a href="Microarchitecture" title="Microarchitecture">microarchitectures</a>. Division (<a href="Modulo_operation" class="mw-redirect" title="Modulo operation">modulo</a>) by a constant can be inverted to become a multiplication by the word-size multiplicative-inverse of that constant. This can be done by the programmer, or by the compiler. Division can also be reduced directly into a series of shift-subtracts and shift-adds, though minimizing the number of such operations required is a daunting problem; the number of machine-language instructions resulting may be more than a dozen and swamp the pipeline. If the microarchitecture has <a href="Hardware_multiply" class="mw-redirect" title="Hardware multiply">hardware multiply</a> <a href="Functional_unit" class="mw-redirect" title="Functional unit">functional units</a>, then the multiply-by-inverse is likely a better approach.
</p><p>We can allow the table size <span class="texhtml"><i>n</i></span> to not be a power of 2 and still not have to perform any remainder or division operation, as these computations are sometimes costly. For example, let <span class="texhtml"><i>n</i></span> be significantly less than <span class="texhtml">2<sup><i>b</i></sup></span>. Consider a <a href="Pseudorandom_number_generator" title="Pseudorandom number generator">pseudorandom number generator</a> function <span class="texhtml"><i>P</i>(key)</span> that is uniform on the interval <span class="texhtml">[0, 2<sup><i>b</i></sup> − 1]</span>. A hash function uniform on the interval <span class="texhtml">[0, <i>n</i> − 1]</span> is <span class="texhtml"><i>n</i> <i>P</i>(key) / 2<sup><i>b</i></sup></span>. We can replace the division by a (possibly faster) right <a href="Bit_shifting" class="mw-redirect" title="Bit shifting">bit shift</a>: <span class="texhtml"><i>n P</i>(key) >> <i>b</i></span>.
</p><p>If keys are being hashed repeatedly, and the hash function is costly, then computing time can be saved by precomputing the hash codes and storing them with the keys. Matching hash codes almost certainly means that the keys are identical. This technique is used for the transposition table in game-playing programs, which stores a 64-bit hashed representation of the board position.
</p>
<div class="mw-heading mw-heading3"><h3 id="Universality">Universality</h3></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Universal_hashing" title="Universal hashing">Universal hashing</a></div>
<p>A <i>universal hashing</i> scheme is a <a href="Randomized_algorithm" title="Randomized algorithm">randomized algorithm</a> that selects a hash function <span class="texhtml"><i>h</i></span> among a family of such functions, in such a way that the probability of a collision of any two distinct keys is <span class="texhtml">1/<i>m</i></span>, where <span class="texhtml"><i>m</i></span> is the number of distinct hash values desired—independently of the two keys. Universal hashing ensures (in a probabilistic sense) that the hash <a href="Function_application" title="Function application">function application</a> will behave as well as if it were using a random function, for any distribution of the input data. It will, however, have more collisions than perfect hashing and may require more operations than a special-purpose hash function.
</p>
<div class="mw-heading mw-heading3"><h3 id="Applicability">Applicability</h3></div>
<p>A hash function that allows only certain table sizes or strings only up to a certain length, or cannot accept a seed (i.e. allow double hashing) is less useful than one that does.
</p><p>A hash function is applicable in a variety of situations. Particularly within cryptography, notable applications include:<sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>
</p>
<ul><li><a href="File_verification" title="File verification">Integrity checking</a>: Identical hash values for different files imply equality, providing a reliable means to detect file modifications.</li>
<li><a href="Key_derivation_function" title="Key derivation function">Key derivation</a>: Minor input changes result in a random-looking output alteration, known as the diffusion property. Thus, hash functions are valuable for key derivation functions.</li>
<li><a href="Message_authentication_code" title="Message authentication code">Message authentication codes</a> (MACs): Through the integration of a confidential key with the input data, hash functions can generate MACs ensuring the genuineness of the data, such as in <a href="HMAC" title="HMAC">HMACs</a>.</li>
<li>Password storage: The password's hash value does not expose any password details, emphasizing the importance of securely storing hashed passwords on the server.</li>
<li><a href="Digital_signature" title="Digital signature">Signatures</a>: Message hashes are signed rather than the whole message.</li></ul>
<div class="mw-heading mw-heading3"><h3 id="Deterministic">Deterministic</h3></div>
<p>A hash procedure must be <a href="Deterministic_algorithm" title="Deterministic algorithm">deterministic</a>—for a given input value, it must always generate the same hash value. In other words, it must be a <a href="Function_(mathematics)" title="Function (mathematics)">function</a> of the data to be hashed, in the mathematical sense of the term. This requirement excludes hash functions that depend on external variable parameters, such as <a href="Pseudo-random_number_generator" class="mw-redirect" title="Pseudo-random number generator">pseudo-random number generators</a> or the time of day. It also excludes functions that depend on the <a href="Memory_address" title="Memory address">memory address</a> of the object being hashed, because the address may change during execution (as may happen on systems that use certain methods of <a href="Garbage_collection_(computer_science)" title="Garbage collection (computer science)">garbage collection</a>), although sometimes rehashing of the item is possible.
</p><p>The determinism is in the context of the reuse of the function. For example, <a href="Python_(programming_language)" title="Python (programming language)">Python</a> adds the feature that hash functions make use of a randomized seed that is generated once when the Python process starts in addition to the input to be hashed.<sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup> The Python hash (<a href="SipHash" title="SipHash">SipHash</a>) is still a valid hash function when used within a single run, but if the values are persisted (for example, written to disk), they can no longer be treated as valid hash values, since in the next run the random value might differ.
</p>
<div class="mw-heading mw-heading3"><h3 id="Defined_range">Defined range</h3></div>
<p>It is often desirable that the output of a hash function have fixed size (but see below). If, for example, the output is constrained to 32-bit integer values, then the hash values can be used to index into an array. Such hashing is commonly used to accelerate data searches.<sup id="cite_ref-algorithms_in_java_11-0" class="reference"><a href="#cite_note-algorithms_in_java-11"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup> Producing fixed-length output from variable-length input can be accomplished by breaking the input data into chunks of specific size. Hash functions used for data searches use some arithmetic expression that iteratively processes chunks of the input (such as the characters in a string) to produce the hash value.<sup id="cite_ref-algorithms_in_java_11-1" class="reference"><a href="#cite_note-algorithms_in_java-11"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Variable_range">Variable range</h3></div>
<p>In many applications, the range of hash values may be different for each run of the program or may change along the same run (for instance, when a hash table needs to be expanded). In those situations, one needs a hash function which takes two parameters—the input data <span class="texhtml"><i>z</i></span>, and the number <span class="texhtml"><i>n</i></span> of allowed hash values.
</p><p>A common solution is to compute a fixed hash function with a very large range (say, <span class="texhtml">0</span> to <span class="texhtml">2<sup>32</sup> − 1</span>), divide the result by <span class="texhtml"><i>n</i></span>, and use the division's <a href="Modulo_operation" class="mw-redirect" title="Modulo operation">remainder</a>. If <span class="texhtml"><i>n</i></span> is itself a power of <span class="texhtml">2</span>, this can be done by <a href="Mask_(computing)" title="Mask (computing)">bit masking</a> and <a href="Bit_shifting" class="mw-redirect" title="Bit shifting">bit shifting</a>. When this approach is used, the hash function must be chosen so that the result has fairly uniform distribution between <span class="texhtml">0</span> and <span class="texhtml"><i>n</i> − 1</span>, for any value of <span class="texhtml"><i>n</i></span> that may occur in the application. Depending on the function, the remainder may be uniform only for certain values of <span class="texhtml"><i>n</i></span>, e.g. <a href="Odd_number" class="mw-redirect" title="Odd number">odd</a> or <a href="Prime_number" title="Prime number">prime numbers</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Variable_range_with_minimal_movement_(dynamic_hash_function)">Variable range with minimal movement (dynamic hash function)</h3></div>
<p>When the hash function is used to store values in a hash table that outlives the run of the program, and the hash table needs to be expanded or shrunk, the hash table is referred to as a dynamic hash table.
</p><p>A hash function that will relocate the minimum number of records when the table is resized is desirable. What is needed is a hash function <span class="texhtml"><i>H</i>(<i>z</i>,<i>n</i>)</span> (where <span class="texhtml"><i>z</i></span> is the key being hashed and <span class="texhtml"><i>n</i></span> is the number of allowed hash values) such that <span class="texhtml"><i>H</i>(<i>z</i>,<i>n</i> + 1) = <i>H</i>(<i>z</i>,<i>n</i>)</span> with probability close to <span class="texhtml"><i>n</i>/(<i>n</i> + 1)</span>.
</p><p><a href="Linear_hashing" title="Linear hashing">Linear hashing</a> and <a href="Spiral_hashing" title="Spiral hashing">spiral hashing</a> are examples of dynamic hash functions that execute in constant time but relax the property of uniformity to achieve the minimal movement property. <a href="Extendible_hashing" title="Extendible hashing">Extendible hashing</a> uses a dynamic hash function that requires space proportional to <span class="texhtml"><i>n</i></span> to compute the hash function, and it becomes a function of the previous keys that have been inserted. Several algorithms that preserve the uniformity property but require time proportional to <span class="texhtml"><i>n</i></span> to compute the value of <span class="texhtml"><i>H</i>(<i>z</i>,<i>n</i>)</span> have been invented.
</p><p>A hash function with minimal movement is especially useful in <a href="Distributed_hash_table" title="Distributed hash table">distributed hash tables</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Data_normalization">Data normalization</h3></div>
<p>In some applications, the input data may contain features that are irrelevant for comparison purposes. For example, when looking up a personal name, it may be desirable to ignore the distinction between upper and lower case letters. For such data, one must use a hash function that is compatible with the data <a href="Equivalence_relation" title="Equivalence relation">equivalence</a> criterion being used: that is, any two inputs that are considered equivalent must yield the same hash value. This can be accomplished by normalizing the input before hashing it, as by upper-casing all letters.
</p>
<div class="mw-heading mw-heading2"><h2 id="Hashing_integer_data_types">Hashing integer data types</h2></div>
<p>There are several common algorithms for hashing integers. The method giving the best distribution is data-dependent. One of the simplest and most common methods in practice is the modulo division method.
</p>
<div class="mw-heading mw-heading3"><h3 id="Identity_hash_function">Identity hash function</h3></div>
<p>If the data to be hashed is small enough, then one can use the data itself (reinterpreted as an integer) as the hashed value. The cost of computing this <i><a href="Identity_function" title="Identity function">identity</a></i> hash function is effectively zero. This hash function is <a href="Perfect_hash_function" title="Perfect hash function">perfect</a>, as it maps each input to a distinct hash value.
</p><p>The meaning of "small enough" depends on the size of the type that is used as the hashed value. For example, in <a href="Java_(programming_language)" title="Java (programming language)">Java</a>, the hash code is a 32-bit integer. Thus the 32-bit integer <code>Integer</code> and 32-bit floating-point <code>Float</code> objects can simply use the value directly, whereas the 64-bit integer <code>Long</code> and 64-bit floating-point <code>Double</code> cannot.
</p><p>Other types of data can also use this hashing scheme. For example, when mapping <a href="Character_string" class="mw-redirect" title="Character string">character strings</a> between <a href="Letter_case" title="Letter case">upper and lower case</a>, one can use the binary encoding of each character, interpreted as an integer, to index a table that gives the alternative form of that character ("A" for "a", "8" for "8", etc.). If each character is stored in 8 bits (as in <a href="Extended_ASCII" title="Extended ASCII">extended ASCII</a><sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">[</span>Notes 2<span class="cite-bracket">]</span></a></sup> or <a href="ISO_Latin_1" class="mw-redirect" title="ISO Latin 1">ISO Latin 1</a>), the table has only 2<sup>8</sup> = 256 entries; in the case of <a href="Unicode" title="Unicode">Unicode</a> characters, the table would have 17 × 2<sup>16</sup> = <span class="nowrap">1<span style="margin-left:.25em;">114</span><span style="margin-left:.25em;">112</span></span> entries.
</p><p>The same technique can be used to map <a href="ISO_3166-1_alpha-2" title="ISO 3166-1 alpha-2">two-letter country codes</a> like "us" or "za" to country names (26<sup>2</sup> = 676 table entries), 5-digit <a href="ZIP_Code" title="ZIP Code">ZIP codes</a> like 13083 to city names (<span class="nowrap">100<span style="margin-left:.25em;">000</span></span> entries), etc. Invalid data values (such as the country code "xx" or the ZIP code 00000) may be left undefined in the table or mapped to some appropriate "null" value.
</p>
<div class="mw-heading mw-heading3"><h3 id="Trivial_hash_function">Trivial hash function</h3></div>
<p>If the keys are uniformly or sufficiently uniformly distributed over the key space, so that the key values are essentially random, then they may be considered to be already "hashed". In this case, any number of any bits in the key may be extracted and collated as an index into the hash table. For example, a simple hash function might mask off the <span class="texhtml mvar" style="font-style:italic;">m</span> least significant bits and use the result as an index into a hash table of size <span class="texhtml">2<sup><i>m</i></sup></span>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Mid-squares">Mid-squares</h3></div>
<p>A mid-squares hash code is produced by squaring the input and extracting an appropriate number of middle digits or bits. For example, if the input is <span class="nowrap">123<span style="margin-left:.25em;">456</span><span style="margin-left:.25em;">789</span></span> and the hash table size <span class="nowrap">10<span style="margin-left:.25em;">000</span></span>, then squaring the key produces <span class="nowrap">15<span style="margin-left:.25em;">241</span><span style="margin-left:.25em;">578</span><span style="margin-left:.25em;">750</span><span style="margin-left:.25em;">190</span><span style="margin-left:.25em;">521</span></span>, so the hash code is taken as the middle 4 digits of the 17-digit number (ignoring the high digit) 8750. The mid-squares method produces a reasonable hash code if there is not a lot of leading or trailing zeros in the key. This is a variant of multiplicative hashing, but not as good because an arbitrary key is not a good multiplier.
</p>
<div class="mw-heading mw-heading3"><h3 id="Division_hashing">Division hashing</h3></div>
<p>A standard technique is to use a modulo function on the key, by selecting a divisor <span class="texhtml mvar" style="font-style:italic;">M</span> which is a prime number close to the table size, so <span class="texhtml"><i>h</i>(<i>K</i>) ≡ <i>K</i> (mod <i>M</i>)</span>. The table size is usually a power of 2. This gives a distribution from <span class="texhtml">{0, <i>M</i> − 1}</span>. This gives good results over a large number of key sets. A significant drawback of division hashing is that division requires multiple cycles on most modern architectures (including <a href="X86" title="X86">x86</a>) and can be 10 times slower than multiplication. A second drawback is that it will not break up clustered keys. For example, the keys 123000, 456000, 789000, etc. modulo 1000 all map to the same address. This technique works well in practice because many key sets are sufficiently random already, and the probability that a key set will be cyclical by a large prime number is small.
</p>
<div class="mw-heading mw-heading3"><h3 id="Algebraic_coding">Algebraic coding</h3></div>
<p>Algebraic coding is a variant of the division method of hashing which uses division by a polynomial modulo 2 instead of an integer to map <span class="texhtml mvar" style="font-style:italic;">n</span> bits to <span class="texhtml mvar" style="font-style:italic;">m</span> bits.<sup id="cite_ref-knuth-1973_3-1" class="reference"><a href="#cite_note-knuth-1973-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup><sup class="reference nowrap"><span title="Pages: 512–513">: 512–513 </span></sup> In this approach, <span class="texhtml"><i>M</i> = 2<sup><i>m</i></sup></span>, and we postulate an <span class="texhtml mvar" style="font-style:italic;">m</span>th-degree polynomial <span class="texhtml"><i>Z</i>(<i>x</i>) = <i>x</i><sup><i>m</i></sup> + ζ<sub><i>m</i>−1</sub><i>x</i><sup><i>m</i>−1</sup> + ⋯ + ζ<sub>0</sub></span>. A key <span class="texhtml"><i>K</i> = (<i>k</i><sub><i>n</i>−1</sub>…<i>k</i><sub>1</sub><i>k</i><sub>0</sub>)<sub>2</sub></span> can be regarded as the polynomial <span class="texhtml"><i>K</i>(<i>x</i>) = <i>k</i><sub><i>n</i>−1</sub><i>x</i><sup><i>n</i>−1</sup> + ⋯ + <i>k</i><sub>1</sub><i>x</i> + <i>k</i><sub>0</sub></span>. The remainder using polynomial arithmetic modulo 2 is <span class="texhtml"><i>K</i>(<i>x</i>) mod <i>Z</i>(<i>x</i>) = <i>h</i><sub><i>m</i>−1</sub><i>x</i><sup><i>m</i>−1</sup> + ⋯ <i>h</i><sub>1</sub><i>x</i> + <i>h</i><sub>0</sub></span>. Then <span class="texhtml"><i>h</i>(<i>K</i>) = (<i>h</i><sub><i>m</i>−1</sub>…<i>h</i><sub>1</sub><i>h</i><sub>0</sub>)<sub>2</sub></span>. If <span class="texhtml"><i>Z</i>(<i>x</i>)</span> is constructed to have <span class="texhtml mvar" style="font-style:italic;">t</span> or fewer non-zero coefficients, then keys which share fewer than <span class="texhtml mvar" style="font-style:italic;">t</span> bits are guaranteed to not collide.
</p><p><span class="texhtml mvar" style="font-style:italic;">Z</span> is a function of <span class="texhtml mvar" style="font-style:italic;">k</span>, <span class="texhtml mvar" style="font-style:italic;">t</span>, and <span class="texhtml mvar" style="font-style:italic;">n</span> (the last of which is a divisor of <span class="texhtml">2<sup><i>k</i></sup> − 1</span>) and is constructed from the <a href="Finite_field" title="Finite field">finite field</a> <span class="texhtml">GF(2<sup><i>k</i></sup>)</span>. <a href="Donald_Knuth" title="Donald Knuth">Knuth</a> gives an example: taking <span class="texhtml">(<i>n</i>,<i>m</i>,<i>t</i>) = (15,10,7)</span> yields <span class="texhtml"><i>Z</i>(<i>x</i>) = <i>x</i><sup>10</sup> + <i>x</i><sup>8</sup> + <i>x</i><sup>5</sup> + <i>x</i><sup>4</sup> + <i>x</i><sup>2</sup> + <i>x</i> + 1</span>. The derivation is as follows:
</p><p>Let <span class="texhtml mvar" style="font-style:italic;">S</span> be the smallest set of integers such that <span class="texhtml">{1,2,…,<i>t</i>} ⊆ <i>S</i></span> and <span class="texhtml">(2<i>j</i> mod <i>n</i>) ∈ <i>S</i> ∀<i>j</i> ∈ <i>S</i></span>.<sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">[</span>Notes 3<span class="cite-bracket">]</span></a></sup>
</p><p>Define <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle P(x)=\prod _{j\in S}(x-\alpha ^{j})}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>P</mi>
<mo stretchy="false">(</mo>
<mi>x</mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<munder>
<mo>∏<!-- ∏ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
<mo>∈<!-- ∈ --></mo>
<mi>S</mi>
</mrow>
</munder>
<mo stretchy="false">(</mo>
<mi>x</mi>
<mo>−<!-- − --></mo>
<msup>
<mi>α<!-- α --></mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle P(x)=\prod _{j\in S}(x-\alpha ^{j})}</annotation>
</semantics>
</math></span><img src="./8ec503eae00278775be2b42f7e2b873f8c6fb063.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.338ex; width:19.329ex; height:5.843ex;" alt="{\displaystyle P(x)=\prod _{j\in S}(x-\alpha ^{j})}" loading="lazy"></span> where <span class="texhtml">α ∈<sup><i>n</i></sup> GF(2<sup><i>k</i></sup>)</span> and where the coefficients of <span class="texhtml"><i>P</i>(<i>x</i>)</span> are computed in this field. Then the degree of <span class="texhtml"><i>P</i>(<i>x</i>) = |<span class="nowrap" style="padding-left:0.1em; padding-right:0.1em;"><i>S</i></span>|</span>. Since <span class="texhtml">α<sup>2<i>j</i></sup></span> is a root of <span class="texhtml"><i>P</i>(<i>x</i>)</span> whenever <span class="texhtml">α<sup><i>j</i></sup></span> is a root, it follows that the coefficients <span class="texhtml"><i>p<sup>i</sup></i></span> of <span class="texhtml"><i>P</i>(<i>x</i>)</span> satisfy <span class="texhtml mvar" style="font-style:italic;"><i>p</i><span class="nowrap"><span style="display:inline-block;margin-bottom:-0.3em;vertical-align:-0.4em;line-height:1.2em;font-size:80%;text-align:left"><sup style="font-size:inherit;line-height:inherit;vertical-align:baseline">2</sup><br><sub style="font-size:inherit;line-height:inherit;vertical-align:baseline"><i>i</i></sub></span></span> = <i>p</i><sub>i</sub></span>, so they are all 0 or 1. If <span class="texhtml"><i>R</i>(<i>x</i>) = <i>r</i><sub><i>n</i>−1</sub><i>x</i><sup><i>n</i>−1</sup> + ⋯ + <i>r</i><sub>1</sub><i>x</i> + <i>r</i><sub>0</sub></span> is any nonzero polynomial modulo 2 with at most <span class="texhtml mvar" style="font-style:italic;">t</span> nonzero coefficients, then <span class="texhtml"><i>R</i>(<i>x</i>)</span> is not a multiple of <span class="texhtml"><i>P</i>(<i>x</i>)</span> modulo 2.<sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>Notes 4<span class="cite-bracket">]</span></a></sup> If follows that the corresponding hash function will map keys with fewer than <span class="texhtml mvar" style="font-style:italic;">t</span> bits in common to unique indices.<sup id="cite_ref-knuth-1973_3-2" class="reference"><a href="#cite_note-knuth-1973-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup><sup class="reference nowrap"><span title="Pages: 542–543">: 542–543 </span></sup>
</p><p>The usual outcome is that either <span class="texhtml mvar" style="font-style:italic;">n</span> will get large, or <span class="texhtml mvar" style="font-style:italic;">t</span> will get large, or both, for the scheme to be computationally feasible. Therefore, it is more suited to hardware or microcode implementation.<sup id="cite_ref-knuth-1973_3-3" class="reference"><a href="#cite_note-knuth-1973-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup><sup class="reference nowrap"><span title="Pages: 542–543">: 542–543 </span></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Unique_permutation_hashing">Unique permutation hashing</h3></div>
<p>Unique permutation hashing has a guaranteed best worst-case insertion time.<sup id="cite_ref-15" class="reference"><a href="#cite_note-15"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Multiplicative_hashing">Multiplicative hashing</h3></div>
<p>Standard multiplicative hashing uses the formula <span class="texhtml"><i>h</i><sub><i>a</i></sub>(<i>K</i>) = <span style="font-size:1em">⌊</span>(<i>aK</i> mod <i>W</i>) / (<i>W</i>/<i>M</i>)<span style="font-size:1em">⌋</span></span>, which produces a hash value in <span class="texhtml">{0, …, <i>M</i> − 1}</span>. The value <span class="texhtml mvar" style="font-style:italic;">a</span> is an appropriately chosen value that should be <a href="Coprime_integers" title="Coprime integers">relatively prime</a> to <span class="texhtml mvar" style="font-style:italic;">W</span>; it should be large, and its binary representation a random mix of 1s and 0s. An important practical special case occurs when <span class="texhtml"><i>W</i> = 2<sup><i>w</i></sup></span> and <span class="texhtml"><i>M</i> = 2<sup><i>m</i></sup></span> are powers of 2 and <span class="texhtml mvar" style="font-style:italic;">w</span> is the machine <a href="Word_size" class="mw-redirect" title="Word size">word size</a>. In this case, this formula becomes <span class="texhtml"><i>h</i><sub><i>a</i></sub>(<i>K</i>) = <span style="font-size:1em">⌊</span>(<i>aK</i> mod 2<sup><i>w</i></sup>) / 2<sup><i>w</i>−<i>m</i></sup><span style="font-size:1em">⌋</span></span>. This is special because arithmetic modulo <span class="texhtml">2<sup><i>w</i></sup></span> is done by default in low-level programming languages and integer division by a power of 2 is simply a right-shift, so, in <a href="C_(programming_language)" title="C (programming language)">C</a>, for example, this function becomes
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="kt">unsigned</span><span class="w"> </span><span class="nf">hash</span><span class="p">(</span><span class="kt">unsigned</span><span class="w"> </span><span class="n">K</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">K</span><span class="p">)</span><span class="w"> </span><span class="o">>></span><span class="w"> </span><span class="p">(</span><span class="n">w</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">m</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>and for fixed <span class="texhtml mvar" style="font-style:italic;">m</span> and <span class="texhtml mvar" style="font-style:italic;">w</span> this translates into a single integer multiplication and right-shift, making it one of the fastest hash functions to compute.
</p><p>Multiplicative hashing is susceptible to a "common mistake" that leads to poor diffusion—higher-value input bits do not affect lower-value output bits.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup> A transmutation on the input which shifts the span of retained top bits down and XORs or ADDs them to the key before the multiplication step corrects for this. The resulting function looks like:<sup id="cite_ref-fibonacci-hashing_8-1" class="reference"><a href="#cite_note-fibonacci-hashing-8"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="kt">unsigned</span><span class="w"> </span><span class="nf">hash</span><span class="p">(</span><span class="kt">unsigned</span><span class="w"> </span><span class="n">K</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">K</span><span class="w"> </span><span class="o">^=</span><span class="w"> </span><span class="n">K</span><span class="w"> </span><span class="o">>></span><span class="w"> </span><span class="p">(</span><span class="n">w</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">m</span><span class="p">);</span><span class="w"> </span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">K</span><span class="p">)</span><span class="w"> </span><span class="o">>></span><span class="w"> </span><span class="p">(</span><span class="n">w</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">m</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Fibonacci_hashing">Fibonacci hashing</h3></div>
<p><a href="Fibonacci_number" class="mw-redirect" title="Fibonacci number">Fibonacci</a> hashing is a form of multiplicative hashing in which the multiplier is <span class="texhtml mvar" style="font-style:italic;">2<sup><i>w</i></sup> / ϕ</span>, where <span class="texhtml mvar" style="font-style:italic;">w</span> is the machine word length and <span class="texhtml mvar" style="font-style:italic;">ϕ</span> (phi) is the <a href="Golden_ratio" title="Golden ratio">golden ratio</a> (approximately 1.618). A property of this multiplier is that it uniformly distributes over the table space, <a href="Blockchain" title="Blockchain">blocks</a> of consecutive keys with respect to any block of bits in the key. Consecutive keys within the high bits or low bits of the key (or some other field) are relatively common. The multipliers for various word lengths are:
</p>
<ul><li>16: <i>a</i> = <span style="display: inline-block; width: 11em">9E37<sub>16</sub></span> = <span class="nowrap">40<span style="margin-left:.25em;">503</span></span><sub>10</sub></li>
<li>32: <i>a</i> = <span style="display: inline-block; width: 11em"><span style="white-space:nowrap">9E37<span style="margin-left:0.25em">79B9</span></span><sub>16</sub></span> = <span class="nowrap">2<span style="margin-left:.25em;">654</span><span style="margin-left:.25em;">435</span><span style="margin-left:.25em;">769</span></span><sub>10</sub></li>
<li>48: <i>a</i> = <span style="display: inline-block; width: 11em"><span style="white-space:nowrap">9E37<span style="margin-left:0.25em">79B9</span><span style="margin-left:0.25em">7F4B</span></span><sub>16</sub></span> = <span class="nowrap">173<span style="margin-left:.25em;">961</span><span style="margin-left:.25em;">102</span><span style="margin-left:.25em;">589</span><span style="margin-left:.25em;">771</span></span><sub>10</sub><sup id="cite_ref-17" class="reference"><a href="#cite_note-17"><span class="cite-bracket">[</span>Notes 5<span class="cite-bracket">]</span></a></sup></li>
<li>64: <i>a</i> = <span style="display: inline-block; width: 11em"><span style="white-space:nowrap">9E37<span style="margin-left:0.25em">79B9</span><span style="margin-left:0.25em">7F4A</span><span style="margin-left:0.25em">7C15</span></span><sub>16</sub></span> = <span class="nowrap">11<span style="margin-left:.25em;">400</span><span style="margin-left:.25em;">714</span><span style="margin-left:.25em;">819</span><span style="margin-left:.25em;">323</span><span style="margin-left:.25em;">198</span><span style="margin-left:.25em;">485</span></span><sub>10</sub></li></ul>
<p>The multiplier should be odd, so the least significant bit of the output is invertible modulo <span class="texhtml">2<sup><i>w</i></sup></span>. The last two values given above are rounded (up and down, respectively) by more than 1/2 of a least-significant bit to achieve this.
</p>
<div class="mw-heading mw-heading3"><h3 id="Zobrist_hashing">Zobrist hashing</h3></div>
<div role="note" class="hatnote navigation-not-searchable">Main articles: <a href="Tabulation_hashing" title="Tabulation hashing">Tabulation hashing</a> and <a href="Zobrist_hashing" title="Zobrist hashing">Zobrist hashing</a></div>
<p><a href="Tabulation_hashing" title="Tabulation hashing">Tabulation hashing</a>, more generally known as <i>Zobrist hashing</i> after <a href="Albert_Lindsey_Zobrist" title="Albert Lindsey Zobrist">Albert Zobrist</a>, is a method for constructing universal families of hash functions by combining table lookup with XOR operations. This algorithm has proven to be very fast and of high quality for hashing purposes (especially hashing of integer-number keys).<sup id="cite_ref-18" class="reference"><a href="#cite_note-18"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup>
</p><p>Zobrist hashing was originally introduced as a means of compactly representing chess positions in computer game-playing programs. A unique random number was assigned to represent each type of piece (six each for black and white) on each space of the board. Thus a table of 64×12 such numbers is initialized at the start of the program. The random numbers could be any length, but 64 bits was natural due to the 64 squares on the board. A position was transcribed by cycling through the pieces in a position, indexing the corresponding random numbers (vacant spaces were not included in the calculation) and XORing them together (the starting value could be 0 (the identity value for XOR) or a random seed). The resulting value was reduced by modulo, folding, or some other operation to produce a hash table index. The original Zobrist hash was stored in the table as the representation of the position.
</p><p>Later, the method was extended to hashing integers by representing each byte in each of 4 possible positions in the word by a unique 32-bit random number. Thus, a table of 2<sup>8</sup>×4 random numbers is constructed. A 32-bit hashed integer is transcribed by successively indexing the table with the value of each byte of the plain text integer and XORing the loaded values together (again, the starting value can be the identity value or a random seed). The natural extension to 64-bit integers is by use of a table of 2<sup>8</sup>×8 64-bit random numbers.
</p><p>This kind of function has some nice theoretical properties, one of which is called <i>3-tuple independence</i>, meaning that every 3-tuple of keys is equally likely to be mapped to any 3-tuple of hash values.
</p>
<div class="mw-heading mw-heading3"><h3 id="Customized_hash_function">Customized hash function</h3></div>
<p>A hash function can be designed to exploit existing entropy in the keys. If the keys have leading or trailing zeros, or particular fields that are unused, always zero or some other constant, or generally vary little, then masking out only the volatile bits and hashing on those will provide a better and possibly faster hash function. Selected divisors or multipliers in the division and multiplicative schemes may make more uniform hash functions if the keys are cyclic or have other redundancies.
</p>
<div class="mw-heading mw-heading2"><h2 id="Hashing_variable-length_data">Hashing variable-length data</h2></div>
<p>When the data values are long (or variable-length) <a href="Character_string" class="mw-redirect" title="Character string">character strings</a>—such as personal names, <a href="URL" title="URL">web page addresses</a>, or mail messages—their distribution is usually very uneven, with complicated dependencies. For example, text in any <a href="Natural_language" title="Natural language">natural language</a> has highly non-uniform distributions of <a href="Character_(computing)" title="Character (computing)">characters</a>, and <a href="Digraph_(computing)" class="mw-redirect" title="Digraph (computing)">character pairs</a>, characteristic of the language. For such data, it is prudent to use a hash function that depends on all characters of the string—and depends on each character in a different way.
</p>
<div class="mw-heading mw-heading3"><h3 id="Middle_and_ends">Middle and ends</h3></div>
<p>Simplistic hash functions may add the first and last <span class="texhtml"><i>n</i></span> characters of a string along with the length, or form a word-size hash from the middle 4 characters of a string. This saves iterating over the (potentially long) string, but hash functions that do not hash on all characters of a string can readily become linear due to redundancies, clustering, or other pathologies in the key set. Such strategies may be effective as a custom hash function if the structure of the keys is such that either the middle, ends, or other fields are zero or some other invariant constant that does not differentiate the keys; then the invariant parts of the keys can be ignored.
</p>
<div class="mw-heading mw-heading3"><h3 id="Character_folding">Character folding</h3></div>
<p>The paradigmatic example of folding by characters is to add up the integer values of all the characters in the string. A better idea is to multiply the hash total by a constant, typically a sizable prime number, before adding in the next character, ignoring overflow. Using exclusive-or instead of addition is also a plausible alternative. The final operation would be a modulo, mask, or other function to reduce the word value to an index the size of the table. The weakness of this procedure is that information may cluster in the upper or lower bits of the bytes; this clustering will remain in the hashed result and cause more collisions than a proper randomizing hash. ASCII byte codes, for example, have an upper bit of 0, and printable strings do not use the last byte code or most of the first 32 byte codes, so the information, which uses the remaining byte codes, is clustered in the remaining bits in an unobvious manner.
</p><p>The classic approach, dubbed the <a href="PJW_hash_function" title="PJW hash function">PJW hash</a> based on the work of <a href="Peter_J._Weinberger" title="Peter J. Weinberger">Peter J. Weinberger</a> at <a href="Bell_Labs" title="Bell Labs">Bell Labs</a> in the 1970s, was originally designed for hashing identifiers into compiler symbol tables as given in the <a href="Compilers%3A_Principles%2C_Techniques%2C_and_Tools" title="Compilers: Principles, Techniques, and Tools">"Dragon Book"</a>.<sup id="cite_ref-19" class="reference"><a href="#cite_note-19"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup> This hash function offsets the bytes 4 bits before adding them together. When the quantity wraps, the high 4 bits are shifted out and if non-zero, <a href="Exclusive_or" title="Exclusive or">xored</a> back into the low byte of the cumulative quantity. The result is a word-size hash code to which a modulo or other reducing operation can be applied to produce the final hash index.
</p><p>Today, especially with the advent of 64-bit word sizes, much more efficient variable-length string hashing by word chunks is available.
</p>
<div class="mw-heading mw-heading3"><h3 id="Word_length_folding">Word length folding</h3></div>
<div role="note" class="hatnote navigation-not-searchable">See also: <a href="Universal_hashing#Hashing_strings" title="Universal hashing">Universal hashing § Hashing strings</a></div>
<p>Modern microprocessors will allow for much faster processing if 8-bit character strings are not hashed by processing one character at a time, but by interpreting the string as an array of 32-bit or 64-bit integers and hashing/accumulating these "wide word" integer values by means of arithmetic operations (e.g. multiplication by constant and bit-shifting). The final word, which may have unoccupied byte positions, is filled with zeros or a specified randomizing value before being folded into the hash. The accumulated hash code is reduced by a final modulo or other operation to yield an index into the table.
</p>
<div class="mw-heading mw-heading3"><h3 id="Radix_conversion_hashing">Radix conversion hashing</h3></div>
<p>Analogous to the way an ASCII or <a href="EBCDIC" title="EBCDIC">EBCDIC</a> character string representing a decimal number is converted to a numeric quantity for computing, a variable-length string can be converted as <span class="texhtml"><i>x</i><sub><i>k</i>−1</sub>a<sup><i>k</i>−1</sup> + <i>x</i><sub><i>k</i>−2</sub>a<sup><i>k</i>−2</sup> + ⋯ + <i>x</i><sub>1</sub><i>a</i> + <i>x</i><sub>0</sub></span>. This is simply a polynomial in a <a href="Radix" title="Radix">radix</a> <span class="texhtml"><i>a</i> > 1</span> that takes the components <span class="texhtml">(<i>x</i><sub>0</sub>,<i>x</i><sub>1</sub>,...,<i>x</i><sub><i>k</i>−1</sub>)</span> as the characters of the input string of length <span class="texhtml"><i>k</i></span>. It can be used directly as the hash code, or a hash function applied to it to map the potentially large value to the hash table size. The value of <span class="texhtml"><i>a</i></span> is usually a prime number large enough to hold the number of different characters in the character set of potential keys. Radix conversion hashing of strings minimizes the number of collisions.<sup id="cite_ref-20" class="reference"><a href="#cite_note-20"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup> Available data sizes may restrict the maximum length of string that can be hashed with this method. For example, a 128-bit word will hash only a 26-character alphabetic string (ignoring case) with a radix of 29; a printable ASCII string is limited to 9 characters using radix 97 and a 64-bit word. However, alphabetic keys are usually of modest length, because keys must be stored in the hash table. Numeric character strings are usually not a problem; 64 bits can count up to <span class="texhtml">10<sup>19</sup></span>, or 19 decimal digits with radix 10.
</p>
<div class="mw-heading mw-heading3"><h3 id="Rolling_hash">Rolling hash</h3></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Rolling_hash" title="Rolling hash">Rolling hash</a></div>
<div role="note" class="hatnote navigation-not-searchable">See also: <a href="Linear_congruential_generator" title="Linear congruential generator">Linear congruential generator</a></div>
<p>In some applications, such as <a href="String_searching_algorithm" class="mw-redirect" title="String searching algorithm">substring search</a>, one can compute a hash function <span class="texhtml"><i>h</i></span> for every <span class="texhtml"><i>k</i></span>-character <a href="Substring" title="Substring">substring</a> of a given <span class="texhtml"><i>n</i></span>-character string by advancing a window of width <span class="texhtml"><i>k</i></span> characters along the string, where <span class="texhtml"><i>k</i></span> is a fixed integer, and <span class="texhtml"><i>n</i> > <i>k</i></span>. The straightforward solution, which is to extract such a substring at every character position in the text and compute <span class="texhtml"><i>h</i></span> separately, requires a number of operations proportional to <span class="texhtml"><i>k</i>·<i>n</i></span>. However, with the proper choice of <span class="texhtml"><i>h</i></span>, one can use the technique of rolling hash to compute all those hashes with an effort proportional to <span class="texhtml"><i>mk</i> + <i>n</i></span> where <span class="texhtml"><i>m</i></span> is the number of occurrences of the substring.<sup id="cite_ref-21" class="reference"><a href="#cite_note-21"><span class="cite-bracket">[</span>16<span class="cite-bracket">]</span></a></sup>
</p><p>The most familiar algorithm of this type is <a href="Rabin-Karp" class="mw-redirect" title="Rabin-Karp">Rabin-Karp</a> with best and average case performance <span class="texhtml"><i>O</i>(<i>n</i>+<i>mk</i>)</span> and worst case <span class="texhtml"><i>O</i>(<i>n</i>·<i>k</i>)</span> (in all fairness, the worst case here is gravely pathological: both the text string and substring are composed of a repeated single character, such as <span class="texhtml"><i>t</i></span>="AAAAAAAAAAA", and <span class="texhtml"><i>s</i></span>="AAA"). The hash function used for the algorithm is usually the <a href="Rabin_fingerprint" title="Rabin fingerprint">Rabin fingerprint</a>, designed to avoid collisions in 8-bit character strings, but other suitable hash functions are also used.
</p>
<div class="mw-heading mw-heading3"><h3 id="Fuzzy_hash">Fuzzy hash</h3></div>
<div class="excerpt-block"><style data-mw-deduplicate="TemplateStyles:r1066933788">
/* start https://en.wikipedia.org/ */
.mw-parser-output .excerpt-hat .mw-editsection-like{font-style:normal}
/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable dablink excerpt-hat selfref">This section is an excerpt from <a href="Fuzzy_hashing" title="Fuzzy hashing">Fuzzy hashing</a>.<span class="mw-editsection-like "><span class="mw-editsection-bracket">[</span><a class="external text external" href="https://en.wikipedia.org/w/index.php?title=Fuzzy_hashing&action=edit">edit</a><span class="mw-editsection-bracket">]</span></span></div><div class="excerpt">
<a href="Fuzzy_hashing" title="Fuzzy hashing">Fuzzy hashing</a>, also known as similarity hashing,<sup id="cite_ref-Fuzzy_hashing_NIST.SP.800-168_22-0" class="reference"><a href="#cite_note-Fuzzy_hashing_NIST.SP.800-168-22"><span class="cite-bracket">[</span>17<span class="cite-bracket">]</span></a></sup> is a technique for <a href="Content_similarity_detection" title="Content similarity detection">detecting data that is similar</a>, but not exactly the same, as other data. This is in contrast to <a href="Cryptographic_hash_function" title="Cryptographic hash function">cryptographic hash functions</a>, which are designed to have significantly different hashes for even minor differences. Fuzzy hashing has been used to identify malware<sup id="cite_ref-Fuzzy_hashing_Beyond_Precision_and_Recall:_Understanding_Uses_(and_Misuses)_of_Similarity_Hashes_in_Binary_Analysis_23-0" class="reference"><a href="#cite_note-Fuzzy_hashing_Beyond_Precision_and_Recall:_Understanding_Uses_(and_Misuses)_of_Similarity_Hashes_in_Binary_Analysis-23"><span class="cite-bracket">[</span>18<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Fuzzy_hashing_Forensic_Malware_Analysis:_The_Value_of_Fuzzy_Hashing_Algorithms_in_Identifying_Similarities_24-0" class="reference"><a href="#cite_note-Fuzzy_hashing_Forensic_Malware_Analysis:_The_Value_of_Fuzzy_Hashing_Algorithms_in_Identifying_Similarities-24"><span class="cite-bracket">[</span>19<span class="cite-bracket">]</span></a></sup> and has potential for other applications, like <a href="Data_loss_prevention" class="mw-redirect" title="Data loss prevention">data loss prevention</a> and detecting multiple versions of code.<sup id="cite_ref-Fuzzy_hashing_ssdeep_25-0" class="reference"><a href="#cite_note-Fuzzy_hashing_ssdeep-25"><span class="cite-bracket">[</span>20<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Fuzzy_hashing_tlsh_26-0" class="reference"><a href="#cite_note-Fuzzy_hashing_tlsh-26"><span class="cite-bracket">[</span>21<span class="cite-bracket">]</span></a></sup></div></div>
<div class="mw-heading mw-heading3"><h3 id="Perceptual_hash">Perceptual hash</h3></div>
<div class="excerpt-block"><div role="note" class="hatnote navigation-not-searchable dablink excerpt-hat selfref">This section is an excerpt from <a href="Perceptual_hashing" title="Perceptual hashing">Perceptual hashing</a>.<span class="mw-editsection-like "><span class="mw-editsection-bracket">[</span><a class="external text external" href="https://en.wikipedia.org/w/index.php?title=Perceptual_hashing&action=edit">edit</a><span class="mw-editsection-bracket">]</span></span></div><div class="excerpt">
<a href="Perceptual_hashing" title="Perceptual hashing">Perceptual hashing</a> is the use of a <a href="Fingerprint_(computing)" title="Fingerprint (computing)">fingerprinting algorithm</a> that produces a snippet, hash, or <a href="Fingerprint_(computing)" title="Fingerprint (computing)">fingerprint</a> of various forms of <a href="Multimedia" title="Multimedia">multimedia</a>.<sup id="cite_ref-Perceptual_hashing_buldas13_27-0" class="reference"><a href="#cite_note-Perceptual_hashing_buldas13-27"><span class="cite-bracket">[</span>22<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Perceptual_hashing_klinger_28-0" class="reference"><a href="#cite_note-Perceptual_hashing_klinger-28"><span class="cite-bracket">[</span>23<span class="cite-bracket">]</span></a></sup> A perceptual hash is a type of <a href="Locality-sensitive_hash" class="mw-redirect" title="Locality-sensitive hash">locality-sensitive hash</a>, which is analogous if <a href="Feature_vector" class="mw-redirect" title="Feature vector">features</a> of the multimedia are similar. This is in contrast to <a href="Cryptographic_hash_function" title="Cryptographic hash function">cryptographic hashing</a>, which relies on the <a href="Avalanche_effect" title="Avalanche effect">avalanche effect</a> of a small change in input value creating a drastic change in output value. Perceptual hash functions are widely used in finding cases of online <a href="Copyright_infringement" title="Copyright infringement">copyright infringement</a> as well as in <a href="Digital_Forensics_Framework" title="Digital Forensics Framework">digital forensics</a> because of the ability to have a correlation between hashes so similar data can be found (for instance with a differing <a href="Digital_watermark" class="mw-redirect" title="Digital watermark">watermark</a>).</div></div>
<div class="mw-heading mw-heading2"><h2 id="Analysis">Analysis</h2></div>
<p>Worst case results for a hash function can be assessed two ways: theoretical and practical. The theoretical worst case is the probability that all keys map to a single slot. The practical worst case is the expected longest probe sequence (hash function + collision resolution method). This analysis considers uniform hashing, that is, any key will map to any particular slot with probability <span class="texhtml">1/<i>m</i></span>, a characteristic of universal hash functions.
</p><p>While <a href="Donald_Knuth" title="Donald Knuth">Knuth</a> worries about adversarial attack on real time systems,<sup id="cite_ref-29" class="reference"><a href="#cite_note-29"><span class="cite-bracket">[</span>24<span class="cite-bracket">]</span></a></sup> Gonnet has shown that the probability of such a case is "ridiculously small". His representation was that the probability of <span class="texhtml"><i>k</i></span> of <span class="texhtml"><i>n</i></span> keys mapping to a single slot is <span class="texhtml">α<sup><i>k</i></sup> / (<i>e</i><sup>α</sup> <i>k</i>!)</span>, where <span class="texhtml"><i>α</i></span> is the load factor, <span class="texhtml"><i>n</i>/<i>m</i></span>.<sup id="cite_ref-30" class="reference"><a href="#cite_note-30"><span class="cite-bracket">[</span>25<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="History">History</h2></div>
<p>The term <i>hash</i> offers a natural analogy with its non-technical meaning (to chop up or make a mess out of something), given how hash functions scramble their input data to derive their output.<sup id="cite_ref-knuth-2000_31-0" class="reference"><a href="#cite_note-knuth-2000-31"><span class="cite-bracket">[</span>26<span class="cite-bracket">]</span></a></sup><sup class="reference nowrap"><span title="Page: 514">: 514 </span></sup> In his research for the precise origin of the term, <a href="Donald_Knuth" title="Donald Knuth">Donald Knuth</a> notes that, while <a href="Hans_Peter_Luhn" title="Hans Peter Luhn">Hans Peter Luhn</a> of <a href="IBM" title="IBM">IBM</a> appears to have been the first to use the concept of a hash function in a memo dated January 1953, the term itself did not appear in published literature until the late 1960s, in Herbert Hellerman's <i>Digital Computer System Principles</i>, even though it was already widespread jargon by then.<sup id="cite_ref-knuth-2000_31-1" class="reference"><a href="#cite_note-knuth-2000-31"><span class="cite-bracket">[</span>26<span class="cite-bracket">]</span></a></sup><sup class="reference nowrap"><span title="Pages: 547–548">: 547–548 </span></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1290876196">
/* start https://en.wikipedia.org/ */
.mw-parser-output .side-box{margin:4px 0;box-sizing:border-box;border:1px solid #aaa;font-size:88%;line-height:1.25em;background-color:var(--background-color-interactive-subtle,#f8f9fa);display:flow-root}.mw-parser-output .infobox .side-box{font-size:100%}.mw-parser-output .side-box-abovebelow,.mw-parser-output .side-box-text{padding:0.25em 0.9em}.mw-parser-output .side-box-image{padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .side-box-imageright{padding:2px 0.9em 2px 0;text-align:center}@media(min-width:500px){.mw-parser-output .side-box-flex{display:flex;align-items:center}.mw-parser-output .side-box-text{flex:1;min-width:0}}@media(min-width:720px){.mw-parser-output .side-box{width:238px}.mw-parser-output .side-box-right{clear:right;float:right;margin-left:1em}.mw-parser-output .side-box-left{margin-right:1em}}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1237033735">
/* start https://en.wikipedia.org/ */
@media print{body.ns-0 .mw-parser-output .sistersitebox{display:none!important}}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}
/* end https://en.wikipedia.org/ */
</style><div class="side-box side-box-right sistersitebox"><style data-mw-deduplicate="TemplateStyles:r1126788409">
/* start https://en.wikipedia.org/ */
.mw-parser-output .plainlist ol,.mw-parser-output .plainlist ul{line-height:inherit;list-style:none;margin:0;padding:0}.mw-parser-output .plainlist ol li,.mw-parser-output .plainlist ul li{margin-bottom:0}
/* end https://en.wikipedia.org/ */
</style>
<div class="side-box-flex">
<div class="side-box-image"><span class="noviewer" typeof="mw:File"></span></div>
<div class="side-box-text plainlist">Look up <i><b><a href="https://en.wiktionary.org/wiki/hash" class="extiw external" title="wiktionary:hash">hash</a></b></i> in Wiktionary, the free dictionary.</div></div>
</div>
<style data-mw-deduplicate="TemplateStyles:r1184024115">
/* start https://en.wikipedia.org/ */
.mw-parser-output .div-col{margin-top:0.3em;column-width:30em}.mw-parser-output .div-col-small{font-size:90%}.mw-parser-output .div-col-rules{column-rule:1px solid #aaa}.mw-parser-output .div-col dl,.mw-parser-output .div-col ol,.mw-parser-output .div-col ul{margin-top:0}.mw-parser-output .div-col li,.mw-parser-output .div-col dd{page-break-inside:avoid;break-inside:avoid-column}
/* end https://en.wikipedia.org/ */
</style><div class="div-col" style="column-width: 33em;">
<ul><li><a href="List_of_hash_functions" title="List of hash functions">List of hash functions</a></li>
<li><a href="Nearest_neighbor_search" title="Nearest neighbor search">Nearest neighbor search</a></li>
<li><a href="Distributed_hash_table" title="Distributed hash table">Distributed hash table</a></li>
<li><a href="Identicon" title="Identicon">Identicon</a></li>
<li><a href="Low-discrepancy_sequence" title="Low-discrepancy sequence">Low-discrepancy sequence</a></li>
<li><a href="Transposition_table" title="Transposition table">Transposition table</a></li></ul></div>
<div class="mw-heading mw-heading2"><h2 id="Notes">Notes</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text">This is useful in cases where keys are devised by a malicious agent, for example in pursuit of a DOS attack.</span>
</li>
<li id="cite_note-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-12">^</a></b></span> <span class="reference-text">Plain <a href="ASCII" title="ASCII">ASCII</a> is a 7-bit character encoding, although it is often stored in 8-bit bytes with the highest-order bit always clear (zero). Therefore, for plain ASCII, the bytes have only 2<sup>7</sup> = 128 valid values, and the character translation table has only this many entries.</span>
</li>
<li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text">For example, for n=15, k=4, t=6, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle S=\{1,2,3,4,5,6,8,10,12,9\}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>S</mi>
<mo>=</mo>
<mo fence="false" stretchy="false">{</mo>
<mn>1</mn>
<mo>,</mo>
<mn>2</mn>
<mo>,</mo>
<mn>3</mn>
<mo>,</mo>
<mn>4</mn>
<mo>,</mo>
<mn>5</mn>
<mo>,</mo>
<mn>6</mn>
<mo>,</mo>
<mn>8</mn>
<mo>,</mo>
<mn>10</mn>
<mo>,</mo>
<mn>12</mn>
<mo>,</mo>
<mn>9</mn>
<mo fence="false" stretchy="false">}</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle S=\{1,2,3,4,5,6,8,10,12,9\}}</annotation>
</semantics>
</math></span><img src="./19e42b87c2ae112644686a3cf5e4c95adfa56d9d.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:30.178ex; height:2.843ex;" alt="{\displaystyle S=\{1,2,3,4,5,6,8,10,12,9\}}" loading="lazy"></span> [Knuth]</span>
</li>
<li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text">Knuth conveniently leaves the proof of this to the reader.</span>
</li>
<li id="cite_note-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-17">^</a></b></span> <span class="reference-text">Unisys large systems.</span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<div class="reflist">
<div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFAggarwalVerma2015" class="citation conference cs1">Aggarwal, Kirti; Verma, Harsh K. (March 19, 2015). <span class="id-lock-subscription" title="Paid subscription required"><a rel="nofollow" class="external text" href="https://ieeexplore.ieee.org/document/7164747"><i>Hash_RC6 — Variable length Hash algorithm using RC6</i></a></span>. 2015 International Conference on Advances in Computer Engineering and Applications (ICACEA). <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1109%2FICACEA.2015.7164747">10.1109/ICACEA.2015.7164747</a><span class="reference-accessdate">. Retrieved <span class="nowrap">January 24,</span> 2023</span>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text">
<ul><li><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://csrc.nist.gov/glossary/term/hash_digest">"hash digest"</a>. <i>Computer Security Resource Center - Glossary</i>. <a href="NIST" class="mw-redirect" title="NIST">NIST</a>.</cite></li>
<li><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://csrc.nist.gov/glossary/term/message_digest">"message digest"</a>. <i>Computer Security Resource Center - Glossary</i>. <a href="NIST" class="mw-redirect" title="NIST">NIST</a>.</cite></li></ul>
</span></li>
<li id="cite_note-knuth-1973-3"><span class="mw-cite-backlink">^ <a href="#cite_ref-knuth-1973_3-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-knuth-1973_3-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-knuth-1973_3-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-knuth-1973_3-3"><sup><i><b>d</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFKnuth1973" class="citation book cs1"><a href="Donald_Knuth" title="Donald Knuth">Knuth, Donald E.</a> (1973). <i>The Art of Computer Programming, Vol. 3, Sorting and Searching</i>. Reading, MA., United States: <a href="Addison-Wesley" title="Addison-Wesley">Addison-Wesley</a>. <a href="Bibcode_(identifier)" class="mw-redirect" title="Bibcode (identifier)">Bibcode</a>:<a rel="nofollow" class="external text" href="https://ui.adsabs.harvard.edu/abs/1973acp..book.....K">1973acp..book.....K</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-0-201-03803-3</bdi>.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite id="CITEREFStokes2002" class="citation web cs1">Stokes, Jon (2002-07-08). <a rel="nofollow" class="external text" href="https://arstechnica.com/gadgets/reviews/2002/07/caching.ars">"Understanding CPU caching and performance"</a>. <i>Ars Technica</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2022-02-06</span></span>.</cite></span>
</li>
<li id="cite_note-handbook_of_applied_cryptography-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-handbook_of_applied_cryptography_6-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFMenezesvan_OorschotVanstone1996" class="citation book cs1">Menezes, Alfred J.; van Oorschot, Paul C.; Vanstone, Scott A (1996). <span class="id-lock-registration" title="Free registration required"><a rel="nofollow" class="external text" href="https://archive.org/details/handbookofapplie0000mene"><i>Handbook of Applied Cryptography</i></a></span>. CRC Press. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-0849385230</bdi>.</cite></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><cite id="CITEREFCastroSierraSeznecIzquierdo2005" class="citation journal cs1">Castro, Julio Cesar Hernandez; et al. (3 February 2005). "The strict avalanche criterion randomness test". <i>Mathematics and Computers in Simulation</i>. <b>68</b> (1). <a href="Elsevier" title="Elsevier">Elsevier</a>: <span class="nowrap">1–</span>7. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1016%2Fj.matcom.2004.09.001">10.1016/j.matcom.2004.09.001</a>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a> <a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:18086276">18086276</a>.</cite></span>
</li>
<li id="cite_note-fibonacci-hashing-8"><span class="mw-cite-backlink">^ <a href="#cite_ref-fibonacci-hashing_8-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-fibonacci-hashing_8-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFSharupke2018" class="citation web cs1">Sharupke, Malte (16 June 2018). <a rel="nofollow" class="external text" href="https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/">"Fibonacci Hashing: The Optimization that the World Forgot"</a>. <i>Probably Dance</i>.</cite></span>
</li>
<li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text"><cite id="CITEREFWagnerLugrin2023" class="citation cs2">Wagner, Urs; Lugrin, Thomas (2023), Mulder, Valentin; Mermoud, Alain; Lenders, Vincent; Tellenbach, Bernhard (eds.), "Hash Functions", <i>Trends in Data Protection and Encryption Technologies</i>, Cham: Springer Nature Switzerland, pp. <span class="nowrap">21–</span>24, <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1007%2F978-3-031-33386-6_5">10.1007/978-3-031-33386-6_5</a></span>, <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-3-031-33386-6</bdi></cite></span>
</li>
<li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.python.org/3/reference/datamodel.html#object.__hash__">"3. Data model — Python 3.6.1 documentation"</a>. <i>docs.python.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2017-03-24</span></span>.</cite></span>
</li>
<li id="cite_note-algorithms_in_java-11"><span class="mw-cite-backlink">^ <a href="#cite_ref-algorithms_in_java_11-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-algorithms_in_java_11-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFSedgewick2002" class="citation book cs1">Sedgewick, Robert (2002). "14. Hashing". <i>Algorithms in Java</i> (3 ed.). Addison Wesley. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-0201361209</bdi>.</cite></span>
</li>
<li id="cite_note-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-15">^</a></b></span> <span class="reference-text"><cite id="CITEREFDolevLahianiHaviv2013" class="citation journal cs1">Dolev, Shlomi; Lahiani, Limor; Haviv, Yinnon (2013). <a rel="nofollow" class="external text" href="https://doi.org/10.1016%2Fj.tcs.2012.12.047">"Unique permutation hashing"</a>. <i>Theoretical Computer Science</i>. <b>475</b>: <span class="nowrap">59–</span>65. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1016%2Fj.tcs.2012.12.047">10.1016/j.tcs.2012.12.047</a></span>.</cite></span>
</li>
<li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text">
<cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.cs.cornell.edu/courses/cs3110/2008fa/lectures/lec21.html">"CS 3110 Lecture 21: Hash functions"</a>. Section "Multiplicative hashing".</cite></span>
</li>
<li id="cite_note-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-18">^</a></b></span> <span class="reference-text"><cite id="CITEREFZobrist1970" class="citation cs2"><a href="Albert_Lindsey_Zobrist" title="Albert Lindsey Zobrist">Zobrist, Albert L.</a> (April 1970), <a rel="nofollow" class="external text" href="https://www.cs.wisc.edu/techreports/1970/TR88.pdf"><i>A New Hashing Method with Application for Game Playing</i></a> <span class="cs1-format">(PDF)</span>, Tech. Rep. 88, Madison, Wisconsin: Computer Sciences Department, University of Wisconsin</cite>.</span>
</li>
<li id="cite_note-19"><span class="mw-cite-backlink"><b><a href="#cite_ref-19">^</a></b></span> <span class="reference-text"><cite id="CITEREFAhoSethiUllman1986" class="citation book cs1"><a href="Alfred_Aho" title="Alfred Aho">Aho, A.</a>; <a href="Ravi_Sethi" title="Ravi Sethi">Sethi, R.</a>; <a href="Jeffrey_Ullman" title="Jeffrey Ullman">Ullman, J. D.</a> (1986). <i>Compilers: Principles, Techniques and Tools</i>. Reading, MA: <a href="Addison-Wesley" title="Addison-Wesley">Addison-Wesley</a>. p. 435. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-201-10088-6</bdi>.</cite></span>
</li>
<li id="cite_note-20"><span class="mw-cite-backlink"><b><a href="#cite_ref-20">^</a></b></span> <span class="reference-text"><cite id="CITEREFRamakrishnaZobel1997" class="citation conference cs1">Ramakrishna, M. V.; Zobel, Justin (1997). <a rel="nofollow" class="external text" href="https://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.18.7520&rep=rep1&type=pdf">"Performance in Practice of String Hashing Functions"</a>. <i>Database Systems for Advanced Applications '97</i>. DASFAA 1997. pp. <span class="nowrap">215–</span>224. <a href="CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a> <span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.7520">10.1.1.18.7520</a></span>. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1142%2F9789812819536_0023">10.1142/9789812819536_0023</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>981-02-3107-5</bdi>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a> <a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:8250194">8250194</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-12-06</span></span>.</cite></span>
</li>
<li id="cite_note-21"><span class="mw-cite-backlink"><b><a href="#cite_ref-21">^</a></b></span> <span class="reference-text"><cite id="CITEREFSingh" class="citation book cs1">Singh, N. B. <a rel="nofollow" class="external text" href="https://books.google.com/books?id=ALIMEQAAQBAJ&dq=rolling+hash&pg=PT102"><i>A Handbook of Algorithms</i></a>. N.B. Singh.</cite></span>
</li>
<li id="cite_note-Fuzzy_hashing_NIST.SP.800-168-22"><span class="mw-cite-backlink"><b><a href="#cite_ref-Fuzzy_hashing_NIST.SP.800-168_22-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFBreitinger2014" class="citation journal cs1">Breitinger, Frank (May 2014). <a rel="nofollow" class="external text" href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-168.pdf">"NIST Special Publication 800-168"</a> <span class="cs1-format">(PDF)</span>. <i>NIST Publications</i>. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.6028%2FNIST.SP.800-168">10.6028/NIST.SP.800-168</a><span class="reference-accessdate">. Retrieved <span class="nowrap">January 11,</span> 2023</span>.</cite></span>
</li>
<li id="cite_note-Fuzzy_hashing_Beyond_Precision_and_Recall:_Understanding_Uses_(and_Misuses)_of_Similarity_Hashes_in_Binary_Analysis-23"><span class="mw-cite-backlink"><b><a href="#cite_ref-Fuzzy_hashing_Beyond_Precision_and_Recall:_Understanding_Uses_(and_Misuses)_of_Similarity_Hashes_in_Binary_Analysis_23-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFPaganiDell'AmicoBalzarotti2018" class="citation conference cs1">Pagani, Fabio; Dell'Amico, Matteo; Balzarotti, Davide (2018-03-13). <a rel="nofollow" class="external text" href="https://pagabuc.me/docs/codaspy18_pagani.pdf">"Beyond Precision and Recall"</a> <span class="cs1-format">(PDF)</span>. <i>Proceedings of the Eighth ACM Conference on Data and Application Security and Privacy</i>. New York, NY, USA: ACM. pp. <span class="nowrap">354–</span>365. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F3176258.3176306">10.1145/3176258.3176306</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>9781450356329</bdi><span class="reference-accessdate">. Retrieved <span class="nowrap">December 12,</span> 2022</span>.</cite></span>
</li>
<li id="cite_note-Fuzzy_hashing_Forensic_Malware_Analysis:_The_Value_of_Fuzzy_Hashing_Algorithms_in_Identifying_Similarities-24"><span class="mw-cite-backlink"><b><a href="#cite_ref-Fuzzy_hashing_Forensic_Malware_Analysis:_The_Value_of_Fuzzy_Hashing_Algorithms_in_Identifying_Similarities_24-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFSarantinosBenzaïdArabiat2016" class="citation book cs1">Sarantinos, Nikolaos; Benzaïd, Chafika; Arabiat, Omar (2016). <a rel="nofollow" class="external text" href="https://ieeexplore.ieee.org/document/7847157">"Forensic Malware Analysis: The Value of Fuzzy Hashing Algorithms in Identifying Similarities"</a>. <a rel="nofollow" class="external text" href="http://roar.uel.ac.uk/5710/1/Forensic%20Malware%20Analysis.pdf"><i>2016 IEEE Trustcom/BigDataSE/ISPA</i></a> <span class="cs1-format">(PDF)</span>. pp. <span class="nowrap">1782–</span>1787. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1109%2FTrustCom.2016.0274">10.1109/TrustCom.2016.0274</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-1-5090-3205-1</bdi>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a> <a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:32568938">32568938</a>. 10.1109/TrustCom.2016.0274.</cite></span>
</li>
<li id="cite_note-Fuzzy_hashing_ssdeep-25"><span class="mw-cite-backlink"><b><a href="#cite_ref-Fuzzy_hashing_ssdeep_25-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFKornblum2006" class="citation journal cs1 cs1-prop-long-vol">Kornblum, Jesse (2006). <a rel="nofollow" class="external text" href="https://www.sciencedirect.com/science/article/pii/S1742287606000764">"Identifying almost identical files using context triggered piecewise hashing"</a>. <i>Digital Investigation</i>. 3, Supplement (September 2006): <span class="nowrap">91–</span>97. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1016%2Fj.diin.2006.06.015">10.1016/j.diin.2006.06.015</a></span><span class="reference-accessdate">. Retrieved <span class="nowrap">June 30,</span> 2022</span>.</cite></span>
</li>
<li id="cite_note-Fuzzy_hashing_tlsh-26"><span class="mw-cite-backlink"><b><a href="#cite_ref-Fuzzy_hashing_tlsh_26-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFOliverChengChen2013" class="citation conference cs1">Oliver, Jonathan; Cheng, Chun; Chen, Yanggui (2013). <a rel="nofollow" class="external text" href="https://github.com/trendmicro/tlsh/blob/master/TLSH_CTC_final.pdf">"TLSH -- A Locality Sensitive Hash"</a> <span class="cs1-format">(PDF)</span>. <i>2013 Fourth Cybercrime and Trustworthy Computing Workshop</i>. IEEE. pp. <span class="nowrap">7–</span>13. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1109%2Fctc.2013.9">10.1109/ctc.2013.9</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-1-4799-3076-0</bdi><span class="reference-accessdate">. Retrieved <span class="nowrap">December 12,</span> 2022</span>.</cite></span>
</li>
<li id="cite_note-Perceptual_hashing_buldas13-27"><span class="mw-cite-backlink"><b><a href="#cite_ref-Perceptual_hashing_buldas13_27-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFBuldasKroonmaaLaanoja2013" class="citation book cs1">Buldas, Ahto; Kroonmaa, Andres; Laanoja, Risto (2013). "Keyless Signatures' Infrastructure: How to Build Global Distributed Hash-Trees". In Riis, Nielson H.; Gollmann, D. (eds.). <i>Secure IT Systems. NordSec 2013</i>. Lecture Notes in Computer Science. Vol. 8208. Berlin, Heidelberg: Springer. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2F978-3-642-41488-6_21">10.1007/978-3-642-41488-6_21</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-3-642-41487-9</bdi>. <q>Keyless Signatures Infrastructure (KSI) is a globally distributed system for providing time-stamping and server-supported digital signature services. Global per-second hash trees are created and their root hash values published. We discuss some service quality issues that arise in practical implementation of the service and present solutions for avoiding single points of failure and guaranteeing a service with reasonable and stable delay. Guardtime AS has been operating a KSI Infrastructure for 5 years. We summarize how the KSI Infrastructure is built, and the lessons learned during the operational period of the service.</q></cite></span>
</li>
<li id="cite_note-Perceptual_hashing_klinger-28"><span class="mw-cite-backlink"><b><a href="#cite_ref-Perceptual_hashing_klinger_28-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFpHash.org" class="citation web cs1">Klinger, Evan; Starkweather, David. <a rel="nofollow" class="external text" href="http://www.phash.org/">"pHash.org: Home of pHash, the open source perceptual hash library"</a>. <i>pHash.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2018-07-05</span></span>. <q>pHash is an open source software library released under the GPLv3 license that implements several perceptual hashing algorithms, and provides a C-like API to use those functions in your own programs. pHash itself is written in C++.</q></cite></span>
</li>
<li id="cite_note-29"><span class="mw-cite-backlink"><b><a href="#cite_ref-29">^</a></b></span> <span class="reference-text"><cite id="CITEREFKnuth1975" class="citation book cs1"><a href="Donald_Knuth" title="Donald Knuth">Knuth, Donald E.</a> (1975). <i>The Art of Computer Programming, Vol. 3, Sorting and Searching</i>. Reading, MA: <a href="Addison-Wesley" title="Addison-Wesley">Addison-Wesley</a>. p. 540.</cite></span>
</li>
<li id="cite_note-30"><span class="mw-cite-backlink"><b><a href="#cite_ref-30">^</a></b></span> <span class="reference-text"><cite id="CITEREFGonnet1978" class="citation techreport cs1">Gonnet, G. (1978). <i>Expected Length of the Longest Probe Sequence in Hash Code Searching</i> (Technical report). Ontario, Canada: <a href="University_of_Waterloo" title="University of Waterloo">University of Waterloo</a>. CS-RR-78-46.</cite></span>
</li>
<li id="cite_note-knuth-2000-31"><span class="mw-cite-backlink">^ <a href="#cite_ref-knuth-2000_31-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-knuth-2000_31-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFKnuth2000" class="citation book cs1"><a href="Donald_Knuth" title="Donald Knuth">Knuth, Donald E.</a> (2000). <i>The Art of Computer Programming, Vol. 3, Sorting and Searching</i> (2. ed., 6. printing, newly updated and rev. ed.). Boston [u.a.]: Addison-Wesley. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-0-201-89685-5</bdi>.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<div class="side-box side-box-right sistersitebox">
<div class="side-box-flex">
<div class="side-box-image"><span class="noviewer" typeof="mw:File"></span></div>
<div class="side-box-text plainlist">Look up <i><b><a href="https://en.wiktionary.org/wiki/hash" class="extiw external" title="wiktionary:hash">hash</a></b></i> in Wiktionary, the free dictionary.</div></div>
</div>
<ul><li><a rel="nofollow" class="external text" href="http://www.sinfocol.org/archivos/2009/11/Goulburn06.pdf">The Goulburn Hashing Function</a> (<a href="Portable_Document_Format" class="mw-redirect" title="Portable Document Format">PDF</a>) by Mayur Patel</li>
<li><a rel="nofollow" class="external text" href="https://dspace5.zcu.cz/bitstream/11025/11784/1/Skala_2010_Corfu-NAUN-Hash.pdf">Hash Function Construction for Textual and Geometrical Data Retrieval</a> (<a href="Portable_Document_Format" class="mw-redirect" title="Portable Document Format">PDF</a>) Latest Trends on Computers, Vol.2, pp. 483–489, CSCC Conference, Corfu, 2010</li></ul>
<div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1236075235">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style></div><div role="navigation" class="navbox" aria-labelledby="Data_structures_and_algorithms145" style="padding:3px"><table class="nowraplinks hlist mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><style data-mw-deduplicate="TemplateStyles:r1239400231">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div id="Data_structures_and_algorithms145" style="font-size:114%;margin:0 4em"><a href="Data_structure" title="Data structure">Data structures</a> and <a href="Algorithm" title="Algorithm">algorithms</a></div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%">Data structures</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Array_(data_structure)" title="Array (data structure)">Array</a></li>
<li><a href="Associative_array" title="Associative array">Associative array</a></li>
<li><a href="Binary_search_tree" title="Binary search tree">Binary search tree</a></li>
<li><a href="Fenwick_tree" title="Fenwick tree">Fenwick tree</a></li>
<li><a href="Graph_(abstract_data_type)" title="Graph (abstract data type)">Graph</a></li>
<li><a href="Hash_table" title="Hash table">Hash table</a></li>
<li><a href="Heap_(data_structure)" title="Heap (data structure)">Heap</a></li>
<li><a href="Linked_list" title="Linked list">Linked list</a></li>
<li><a href="Queue_(abstract_data_type)" title="Queue (abstract data type)">Queue</a></li>
<li><a href="Segment_tree" title="Segment tree">Segment tree</a></li>
<li><a href="Stack_(abstract_data_type)" title="Stack (abstract data type)">Stack</a></li>
<li><a href="String_(computer_science)" title="String (computer science)">String</a></li>
<li><a href="Tree_(abstract_data_type)" title="Tree (abstract data type)">Tree</a></li>
<li><a href="Trie" title="Trie">Trie</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Algorithms and <a href="Algorithmic_paradigm" title="Algorithmic paradigm">algorithmic paradigms</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Backtracking" title="Backtracking">Backtracking</a></li>
<li><a href="Binary_search" title="Binary search">Binary search</a></li>
<li><a href="Breadth-first_search" title="Breadth-first search">Breadth-first search</a></li>
<li><a href="Brute-force_search" title="Brute-force search">Brute-force search</a></li>
<li><a href="Depth-first_search" title="Depth-first search">Depth-first search</a></li>
<li><a href="Divide-and-conquer_algorithm" title="Divide-and-conquer algorithm">Divide and conquer</a></li>
<li><a href="Dynamic_programming" title="Dynamic programming">Dynamic programming</a></li>
<li><a href="Graph_traversal" title="Graph traversal">Graph traversal</a></li>
<li><a href="Fold_(higher-order_function)" title="Fold (higher-order function)">Fold</a></li>
<li><a href="Greedy_algorithm" title="Greedy algorithm">Greedy</a></li>
<li><a href="Minimax" title="Minimax">Minimax</a></li>
<li><a href="Online_algorithm" title="Online algorithm">Online</a></li>
<li><a href="Randomized_algorithm" title="Randomized algorithm">Randomized</a></li>
<li><a href="Recursion_(computer_science)" title="Recursion (computer science)">Recursion</a></li>
<li><a href="Root-finding_algorithm" title="Root-finding algorithm">Root-finding</a></li>
<li><a href="Sorting_algorithm" title="Sorting algorithm">Sorting</a></li>
<li><a href="Streaming_algorithm" title="Streaming algorithm">Streaming</a></li>
<li><a href="Sweep_line_algorithm" title="Sweep line algorithm">Sweep line</a></li>
<li><a href="String-searching_algorithm" title="String-searching algorithm">String-searching</a></li>
<li><a href="Topological_sorting" title="Topological sorting">Topological sorting</a></li></ul>
</div></td></tr><tr><td class="navbox-abovebelow" colspan="2"><div>
<ul><li><a href="List_of_data_structures" title="List of data structures">List of data structures</a></li>
<li><a href="List_of_algorithms" title="List of algorithms">List of algorithms</a></li></ul>
</div></td></tr></tbody></table></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-31" href="https://en.wikipedia.org/wiki/?title=Hash_function&oldid=1303550871">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>